<template>
  <div>
    <navTop :title="name"></navTop>
    <img class="title_img" src="~@/assets/img/gk/bt1.png" alt="">
    <div class="content" v-html="data1"></div>
    <img class="title_img" src="~@/assets/img/gk/bt2.png" alt="">
    <div class="content" v-html="data2"></div>
    <img class="title_img" src="~@/assets/img/gk/bt3.png" alt="">
    <div class="content" v-html="data3"></div>
    <img class="title_img" src="~@/assets/img/gk/bt4.png" alt="">
    <div class="content" v-html="data4"></div>
    <img class="title_img" src="~@/assets/img/gk/bt5.png" alt="">
    <div class="content" v-html="data5"></div>
    <img class="title_img" src="~@/assets/img/gk/bt6.png" alt="">
    <div class="content" v-html="data6"></div>
    <img class="b_img" src="~@/assets/img/gk_bottom.gif" alt="">
  </div>
</template>
<script>
import { chengwuGk,common } from '@/api/api.js'
import wx from 'weixin-js-sdk'; // 引入wxjs
import navTop from '@/components/navTop.vue'
export default {
  components: {
    navTop
  },
  data() {
    return {
      name: '',
      data1: '',
      data2: '',
      data3: '',
      data4: '',
      data5: '',
      data6: '',
    }
  },
  created() {
    this.$toast.loading({
      message: '加载中...',
      forbidClick: true,
    });
    chengwuGk().then(res => {
      this.name = res.data.name
      let newContent = res.data.content.replace(/<img[^>]*>/gi, function(match, capture) {
        match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
        match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
        match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
        return match;
      });
      newContent = newContent.replace(/\<img/gi,
          '<img style="max-width:100%;height:auto;display:block;margin:0px auto;"');
      res.data.content = newContent
      this.data1 = res.data.content
      this.$toast.clear()
    })
    chengwuGk({type_id:2}).then(res => {
      let newContent = res.data.content.replace(/<img[^>]*>/gi, function(match, capture) {
        match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
        match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
        match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
        return match;
      });
      newContent = newContent.replace(/\<img/gi,
          '<img style="max-width:100%;height:auto;display:block;margin:0px auto;"');
      res.data.content = newContent
      this.data2 = res.data.content
      this.$toast.clear()
    })
    chengwuGk({type_id:3}).then(res => {
      let newContent = res.data.content.replace(/<img[^>]*>/gi, function(match, capture) {
        match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
        match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
        match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
        return match;
      });
      newContent = newContent.replace(/\<img/gi,
          '<img style="max-width:100%;height:auto;display:block;margin:0px auto;"');
      res.data.content = newContent
      this.data3 = res.data.content
      this.$toast.clear()
    })
    chengwuGk({type_id:4}).then(res => {
      let newContent = res.data.content.replace(/<img[^>]*>/gi, function(match, capture) {
        match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
        match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
        match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
        return match;
      });
      newContent = newContent.replace(/\<img/gi,
          '<img style="max-width:100%;height:auto;display:block;margin:0px auto;"');
      res.data.content = newContent
      this.data4 = res.data.content
      this.$toast.clear()
    })
    chengwuGk({type_id:5}).then(res => {
      let newContent = res.data.content.replace(/<img[^>]*>/gi, function(match, capture) {
        match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
        match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
        match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
        return match;
      });
      newContent = newContent.replace(/\<img/gi,
          '<img style="max-width:100%;height:auto;display:block;margin:0px auto;"');
      res.data.content = newContent
      this.data5 = res.data.content
      this.$toast.clear()
    })
    chengwuGk({type_id:6}).then(res => {
      let newContent = res.data.content.replace(/<img[^>]*>/gi, function(match, capture) {
        match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
        match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
        match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
        return match;
      });
      newContent = newContent.replace(/\<img/gi,
          '<img style="max-width:100%;height:auto;display:block;margin:0px auto;"');
      res.data.content = newContent
      this.data6 = res.data.content
      this.$toast.clear()
    })
    this.getShareInfo()
  },
  methods: {
    getShareInfo() {
      let url = window.location.href
      common.getJssdk({url:btoa(url)}).then(res => {
        const config = res.data;
        wx.config({
          debug:false,
          appId: config.appId,  // appID 公众号的唯一标识
          timestamp: config.timestamp, // 生成签名的时间戳
          nonceStr: config.nonceStr, //  生成签名的随机串
          signature: config.signature, // 生成的签名
          jsApiList: [
            'updateAppMessageShareData',
            'updateTimelineShareData',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone',
          ]
        });

        wx.ready(() => {
          var shareData = {
            title: '成武概况 | 一码投成武',
            desc: '成武新韵，活力之城邀您携手同行',
            link: window.location.href,
            imgUrl:'https://guizhou-oss.oss-cn-guiyang-gzdata-d01-a.res.gzdata.com.cn/cwh5/video/cwlogo.png'
          };
          //点击要去分享
          wx.updateAppMessageShareData(shareData);
          wx.updateTimelineShareData(shareData);
          wx.onMenuShareTimeline(shareData);
          wx.onMenuShareAppMessage(shareData);
          wx.onMenuShareQQ(shareData);
          wx.onMenuShareWeibo(shareData);
          wx.onMenuShareQZone(shareData);
        });
      });
    },
  }
}
</script>
<style scoped lang="scss">
.content{
  margin: 15px;
}
.b_img{
  width: 100%;
  height: auto;
  display: block;
}
.title_img{
  width: calc(100% - 30px);
  margin-left: 15px;
  margin-top: 60px;
}
</style>